<template>
  <div class="goods-item" @click="itemClick">
    <img v-lazy="coverImgUrl" alt="" :key="coverImgUrl">
    <div class="goods-item-desc">
      <p>{{goodsItem.name}}</p>
      <span class="play-count">播放 {{goodsItem.playCount}}</span>
      <span class="comment-count">评论 {{goodsItem.commentCount}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'GoodsListItem',
    props: {
      goodsItem: {
        type: Object,
        default() {
          return {}
        }
      }
    },
    computed: {
      coverImgUrl() {
        return this.goodsItem.coverImgUrl || this.goodsItem.picUrl
      }
    },
    methods: {
      itemClick() {
        this.$router.push({
          path: '/detail',
          query: {
            id: this.goodsItem.id
          }
        })
      }
    }
  }
</script>

<style scoped>
  .goods-item {
    width: 48%;
  }

  .goods-item img {
    width: 100%;
    border-radius: 5px;
  }

  .goods-item p {
    font-size: 14px;
    /* 文字一行显示 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .goods-item span {
    display: inline-block;
    margin: 5px 5px 5px 0;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .play-count {
    width: 50%;
    color: var(--color-high-text);
  }

  .comment-count {
    width: 40%;
  }
</style>